from selenium import webdriver
import allure
from selenium.webdriver.common.by import By


class BasePage:
    def __init__(self):
        # 选择浏览器驱动
        self.driver = webdriver.Chrome()
        # 选择URL
        self.driver.get('http://localhost:8013/web/index.html#/login')
        # 设置窗口最大化和隐型等待2秒
        self.driver.maximize_window()
        self.driver.implicitly_wait(2)

    @allure.step('使用ID定位元素')
    def by_id(self, *log):
        return self.driver.find_element(By.ID, *log)

    @allure.step('使用CLASS_NAME定位元素')
    def by_class_name(self, *log):
        return self.driver.find_element(By.CLASS_NAME, *log)

    @allure.step('使用CLASS_NAME定位多个元素')
    def by_class_names(self, *log):
        return self.driver.find_elements(By.CLASS_NAME, *log)

    @allure.step('使用NAME定位元素')
    def by_name(self, *log):
        return self.driver.find_element(By.NAME, *log)

    @allure.step('使用LINK_TEXT定位元素')
    def by_link_text(self, *log):
        return self.driver.find_element(By.LINK_TEXT, *log)

    @allure.step('使用TAG_NAME定位元素')
    def by_tag_name(self, *log):
        return self.driver.find_element(By.TAG_NAME, *log)

    @allure.step('使用CSS_SELECTOR定位元素')
    def by_css_selector(self, *log):
        return self.driver.find_element(By.CSS_SELECTOR, *log)

    @allure.step('使用XPATH定位元素')
    def by_xpath(self, *log):
        return self.driver.find_element(By.XPATH, *log)

    @allure.step('使用XPATH定位多个元素')
    def by_xpaths(self, *log):
        return self.driver.find_elements(By.XPATH, *log)
